package com.pv.bfc.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.pv.bfc.dao.FolderRepository;

public class FolderDocumentsController extends AbstractController {

	private FolderRepository folderRepo;

	private static final String PARAM_VIEW = "view";

	private static final Log logger = LogFactory
			.getLog(FolderDocumentsController.class);

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		logger.info("IN - FolderDocumentsController - handleRequestInternal");
		Integer folderId = ServletRequestUtils.getRequiredIntParameter(req,
				"folder");

		/*
		 * Integer docId = ServletRequestUtils.getIntParameter(req, "document");
		 * String paramterReq = ServletRequestUtils.getStringParameter(req,
		 * "param");
		 * 
		 * System.out.println("paramterReq" + paramterReq);
		 */

		/*
		 * if (paramterReq != null && paramterReq.equalsIgnoreCase("sendOrder"))
		 * { Document doc = folderRepo.retrieveDocumentById(docId);
		 * sendOrder(document); }
		 */

		String view = ServletRequestUtils.getStringParameter(req, PARAM_VIEW);
		ModelAndView mav = new ModelAndView(view);
		mav.addObject(folderRepo.retrieveFolderById(folderId));

		logger.info("OUT - FolderDocumentsController - handleRequestInternal");
		return mav;
	}

	public void setFolderRepo(FolderRepository folderRepo) {
		this.folderRepo = folderRepo;
	}
}
